package hr.galerija.client.custom;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException;
import com.google.gwt.user.client.rpc.InvocationException;
import com.smartgwt.client.util.SC;

public abstract class AppAsyncCallback<T> implements AsyncCallback<T> {

	@Override
	public final void onFailure(Throwable arg0) {
		System.out.println("failure: " + arg0.getMessage());

		try {
			throw arg0;
		} catch (IncompatibleRemoteServiceException e) {
			// this client is not compatible with the server; cleanup and refresh the 
			// browser
			//SC.say("IncompatibleRemoteServiceException: " + arg0.getMessage());
			Window.alert("IncompatibleRemoteServiceException");
		} catch (InvocationException e) {
			// the call didn't complete cleanly
			//SC.say("InvocationException: " + arg0.getMessage());
			Window.alert("InvocationException");
		} catch (Throwable e) {
			// last resort -- a very unexpected exception
			SC.say("Throwable: " + arg0.getMessage());
			//Window.alert("Throwable");
		}
		
		// TODO add custom exception if needed
	}
}
